#ifndef CAPTURETHREAD_H
#define CAPTURETHREAD_H

#include <QThread>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
#include "libv4l2.h"
#include "libv4lconvert.h"
#include "global.h"

class CaptureThread : public QThread
{
public:
    explicit CaptureThread(QObject *parent = 0);
    ~CaptureThread();
    bool devam;


//    static void xioctl(int fh, int request, void *arg)
//    {
//            int ret;

//            do {
//                    ret = v4l2_ioctl(fh, request, arg);
//            } while (ret == -1 && ((errno == EINTR) || (errno == EAGAIN)));

//            if (ret == -1) {
//                    fprintf(stderr, "error %d, %s\n", errno, strerror(errno));
//                    return;
//            }
//    };
    void run();

public:


    void stopCapture();
    void startCapture();

private:
    QWidget *parent;
    enum v4l2_buf_type              type;
    fd_set                          fds;
    struct timeval                  tv;
    int                             ret, fd;
    unsigned int                    i;
    char                            out_name[256];
    FILE                            *fout;
    PSDLMODULE                      pSdlModule;
    PTAVSDLYUVSURFACE               pSurface;

    struct VidioBuffer {
            void   *start;
            size_t length;
    };
    struct VidioBuffer                   *videio_buffers;
};






#endif // CAPTURETHREAD_H
